<?php
// +----------------------------------------------------------------------
// | Author: 闪电 <573725206@qq.com>
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Common\Controller\AuthController;

class NavController extends AuthController {
	//列表
	public function index() {
		//添置按钮
		$array[] = array('title' => '添加栏目', 'url' => U('add'), 'class' => 'primary', 'type' => 'button', 'target' => 'myModal');
		$this->assign('add_button', add_button($array));

		$number = 41; //模型id
		//获取模型表单数据
		$ControllerName = D('Admin/Model');
		$html = $ControllerName->FormLayout($number, '', '', $this->navListColumn());
		$this->assign('mid', $number);
		$this->assign('form', $html);

		$this->assign('FormConfig', array('title' => '添加栏目', 'url' => U('add', array('mid' => $number))));
		$type[] = array('title' => '列表', 'url' => 'lists', 'class' => 'default', 'type' => 'rom');
		$type[] = array('title' => '编缉', 'url' => 'rom', 'class' => 'default', 'type' => 'rom');
		$type[] = array('title' => '删除', 'url' => 'Index/del', 'class' => 'danger', 'type' => 'delete');
		$this->assign('rollback', 'navListColumn');
		$this->assign('array', $type);
		$this->display();

	}
	//内容列表
	public function lists() {
		$id = I('get.id', '', 'intval');
		$m = I('get.mid', '', 'intval');
		session('romid', $id);
		if (!$id) {
			return false;
		}
		$infos = M(GetModelTable($m))->where(array('id' => $id))->find();

		$mid = $infos['suoshumoxing'];

		$name = return_one(cache_table('model', array('id' => $mid)));
		//添置按钮
		if ($infos['shifoukejianeirong'] == '可以') {
			$array[] = array('title' => '添加' . $name['name'], 'url' => U('add'), 'class' => 'primary', 'type' => 'button', 'target' => 'myModal');
			$this->assign('add_button', add_button($array));
		}

		//表单数据模型
		$this->FormHtml(intval($mid));

		$this->assign('FormConfig', array('title' => '添加' . $name['name'], 'url' => U('add', array('mid' => $mid,'navid'=>$id))));
		$type[] = array('title' => '浏览', 'url' => 'Home/Index/doc', 'class' => 'default', 'type' => 'postU','columnid'=>$id);
		$type[] = array('title' => '编缉', 'url' => 'roms', 'class' => 'default', 'type' => 'rom');
		$type[] = array('title' => '删除', 'url' => 'Index/del', 'class' => 'danger', 'type' => 'delete');
		$this->assign('array', $type);
		//查询对应栏目
		$this->assign("where",array('browse'=>$id));
		$this->display('Public/_List');

	}
	//栏目导航
	public function channel($mid = 44) {
		$mid = $mid;
		$name = cache_table('model', array('id' => $mid));
		$name = $name['0'];
		//添置按钮
		$array[] = array('title' => '添加' . $name['name'], 'url' => U('add'), 'class' => 'primary', 'type' => 'button', 'target' => 'myModal');
		$this->assign('add_button', add_button($array));

		//表单数据模型
		$this->FormHtml($mid);
		$this->assign('FormConfig', array('title' => '添加' . $name['name'], 'url' => U('add', array('mid' => $mid))));
		$type[] = array('title' => '编缉', 'url' => 'Customer/rom', 'class' => 'default', 'type' => 'rom');
		$type[] = array('title' => '删除', 'url' => 'Index/del', 'class' => 'danger', 'type' => 'delete');
		$this->assign('array', $type);
		$this->display('Public/_List');
	}
	//所属分类分隔
	private function navListColumn($id) {
		//栏目分类
		$nav = M(GetModelTable(41))->field(true)->select();
		$options = get_tree_option($nav, 0);
		$html .= "<div class='form-group' id='lanmum'>";
		$html .= "<label class='control-label'>所属分类<span class='Validform_checktip'></span></label>";
		$html .= "<div class='controls'>";

		$html .= "<select class='selectpicker' data-live-search='true' name='pid' datatype='*'>";
		if (!$id) {
			$selected = 'selected';
		}
		$html .= "<option type='radio' value='0' {$selected}>--根分类--</option>";
		foreach ($options as $op) {
			if ($op['id'] == $id) {
				$html .= '<option value="' . $op['pid'] . '" selected>' . str_repeat("-", $op['depth'] * 4) . $op['lanmumingcheng'] . '</option>';
			} else {
				$html .= '<option value="' . $op['id'] . '">' . str_repeat("-", $op['depth'] * 4) . $op['lanmumingcheng'] . '</option>';
			}

		}
		$html .= "</select>";
		$html .= "</div>";
		$html .= "</div>";
		return $html;
	}
	//新增
	public function add() {
		if (IS_POST) {
			//记录栏目id
			$_POST['browse']=I('get.navid','','intval');

			$this->PublicDataModel(I('get.mid', '', 'intval'));
		}
	}
	public function rom() {
		$ControllerName = D('Admin/Model');
		$mid = I('get.mid', '', 'intval');
		$id = I('get.id', '', 'intval');
		if (IS_POST) {
			$this->PublicDataModel($mid, $id, U('index'));
		} else {
			//获取模型表单数据

			$html = $ControllerName->FormLayout($mid, $id, '', $this->navListColumn($id));
			$this->assign('mid', $mid);
			$this->assign('form', $html);
			$this->display('Public/_Form');
		}
	}
	public function roms() {
		$mid = I('get.mid', '', 'intval');
		$id = I('get.id', '', 'intval');
		if (IS_POST) {
			$this->PublicDataModel($mid, $id, U('lists', array('mid' => 41, 'id' => session('romid'))));
		} else {
			$this->PublicDataModel($mid, $id);
		}
	}
	//单页管理
	public function Singlepage() {
		$this->channel(intval(45));
	}

}
